package com.jl.easybuysys.web;

import com.jl.easybuysys.model.EbProduct;
import com.jl.easybuysys.service.EbProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/product")
public class EbProductController {
    @Autowired
    private EbProductService ebProductService;
    @RequestMapping("/detail")
    public String detail(Model model, int epId){
        //1.TODO 调用service根据id查询商品信息
        EbProduct ebProduct = ebProductService.detail(epId);
        //2.TODO 将数据绑定model--数据
        model.addAttribute("product",ebProduct);
        //3.TODO 返回view--html
        return "product-view";
    }
    @RequestMapping("/add_car")
    public String addCar(int epId, HttpServletRequest request){
        //1.TODO 调用service将商品放入到购物车
        ebProductService.addCar(epId,request);
        //2.TODO 绑定数据到model--数据
        //不需要，因为在service已经将数据放入到session中了
        //3.TODO 返回view--html
        return "shopping";
    }
    @RequestMapping("/pay")
    public String pay(){
        return "shopping-result";
    }
}

